{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 主函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "import configure\n",
    "from ScoreGenerator import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "population_size = 1000\n",
    "dna_length = 10\n",
    "mute_rate = 0.1\n",
    "modifiers = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]\n",
    "target_score = 0.8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "---------------------------------------------\n",
      "Cumulative: 0.4844149435937381\n",
      "    Motion:       0.6745993200582807\n",
      "    Consonance:   0.7851239669421488\n",
      "    Consistency:  0.831946755407654\n",
      "    Macroharmony: 0.225\n",
      "    Centricity:   0.4\n",
      "    Cohesion:     0.6161137440758293\n",
      "    Note Length:  0.399800099950025\n",
      "    Octave:       0.2608995668407107\n",
      "    Common Notes: 0.1662510390689942\n",
      "---------------------------------------------\n",
      "Cumulative: 0.5310678301882609\n",
      "    Motion:       0.6083439761600681\n",
      "    Consonance:   0.7024793388429752\n",
      "    Consistency:  0.6655574043261232\n",
      "    Macroharmony: 0.65\n",
      "    Centricity:   0.6\n",
      "    Cohesion:     0.6431535269709543\n",
      "    Note Length:  0.399800099950025\n",
      "    Octave:       0.2608995668407107\n",
      "    Common Notes: 0.24937655860349128\n",
      "---------------------------------------------\n",
      "Cumulative: 0.5624590003600157\n",
      "    Motion:       0.676458067262665\n",
      "    Consonance:   0.7644628099173554\n",
      "    Consistency:  0.6655574043261232\n",
      "    Macroharmony: 0.8\n",
      "    Centricity:   0.6666666666666666\n",
      "    Cohesion:     0.6742738589211618\n",
      "    Note Length:  0.29985007496251875\n",
      "    Octave:       0.1831871626430205\n",
      "    Common Notes: 0.3316749585406302\n",
      "---------------------------------------------\n",
      "Cumulative: 0.5798211491157629\n",
      "    Motion:       0.465799886941775\n",
      "    Consonance:   0.9259259259259259\n",
      "    Consistency:  0.7481296758104738\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.19999999999999996\n",
      "    Cohesion:     0.5939226519337016\n",
      "    Note Length:  0.29985007496251875\n",
      "    Octave:       0.32469611986681096\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.6122939768925376\n",
      "    Motion:       0.6014697569248162\n",
      "    Consonance:   0.9426229508196722\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 0.65\n",
      "    Centricity:   0.4\n",
      "    Cohesion:     0.649171270718232\n",
      "    Note Length:  0.29985007496251875\n",
      "    Octave:       0.3107879911431521\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.6382398852293151\n",
      "    Motion:       0.6297343131712831\n",
      "    Consonance:   0.9426229508196722\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 0.8\n",
      "    Centricity:   0.4\n",
      "    Cohesion:     0.7044198895027624\n",
      "    Note Length:  0.29985007496251875\n",
      "    Octave:       0.3107879911431521\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.6760453689957805\n",
      "    Motion:       0.7134531325886353\n",
      "    Consonance:   0.9426229508196722\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.5\n",
      "    Cohesion:     0.7109004739336492\n",
      "    Note Length:  0.29985007496251875\n",
      "    Octave:       0.2608379411931021\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.6809032714213762\n",
      "    Motion:       0.788015828151498\n",
      "    Consonance:   0.8950617283950618\n",
      "    Consistency:  0.9975062344139651\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.3999999999999999\n",
      "    Cohesion:     0.6629834254143646\n",
      "    Note Length:  0.399800099950025\n",
      "    Octave:       0.32469611986681096\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7019610980160322\n",
      "    Motion:       0.7003957037874504\n",
      "    Consonance:   0.9426229508196722\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.6666666666666667\n",
      "    Cohesion:     0.6906077348066297\n",
      "    Note Length:  0.3498250874562719\n",
      "    Octave:       0.3107879911431521\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7019610980160322\n",
      "    Motion:       0.7003957037874504\n",
      "    Consonance:   0.9426229508196722\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.6666666666666667\n",
      "    Cohesion:     0.6906077348066297\n",
      "    Note Length:  0.3498250874562719\n",
      "    Octave:       0.3107879911431521\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7057297055155611\n",
      "    Motion:       0.7343131712832108\n",
      "    Consonance:   0.9426229508196722\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.6666666666666667\n",
      "    Cohesion:     0.6906077348066297\n",
      "    Note Length:  0.3498250874562719\n",
      "    Octave:       0.3107879911431521\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7252369164563779\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.9426229508196722\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.6666666666666667\n",
      "    Cohesion:     0.7596685082872927\n",
      "    Note Length:  0.399800099950025\n",
      "    Octave:       0.3107879911431521\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7300904558330731\n",
      "    Motion:       0.7569248162803843\n",
      "    Consonance:   0.9426229508196722\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.6666666666666667\n",
      "    Cohesion:     0.7872928176795579\n",
      "    Note Length:  0.4497751124437781\n",
      "    Octave:       0.3107879911431521\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7356432349990457\n",
      "    Motion:       0.7569248162803843\n",
      "    Consonance:   0.9426229508196722\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.6666666666666667\n",
      "    Cohesion:     0.7872928176795579\n",
      "    Note Length:  0.49975012493753124\n",
      "    Octave:       0.3107879911431521\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7449646216645474\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.9426229508196722\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.6666666666666667\n",
      "    Cohesion:     0.7872928176795579\n",
      "    Note Length:  0.5497251374312844\n",
      "    Octave:       0.3107879911431521\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7449646216645474\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.9426229508196722\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.6666666666666667\n",
      "    Cohesion:     0.7872928176795579\n",
      "    Note Length:  0.5497251374312844\n",
      "    Octave:       0.3107879911431521\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7474480331202682\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.9426229508196722\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.6666666666666667\n",
      "    Cohesion:     0.7596685082872927\n",
      "    Note Length:  0.5997001499250375\n",
      "    Octave:       0.3107879911431521\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7505174008305198\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.9426229508196722\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.6666666666666667\n",
      "    Cohesion:     0.7872928176795579\n",
      "    Note Length:  0.5997001499250375\n",
      "    Octave:       0.3107879911431521\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.758419705571578\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.8606557377049181\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.7142857142857143\n",
      "    Cohesion:     0.7872928176795579\n",
      "    Note Length:  0.6496751624187906\n",
      "    Octave:       0.36628188681462825\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7705462239022444\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.9836065573770493\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.7142857142857143\n",
      "    Cohesion:     0.7734806629834253\n",
      "    Note Length:  0.6496751624187906\n",
      "    Octave:       0.36628188681462825\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7705462239022444\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.9836065573770493\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.7142857142857143\n",
      "    Cohesion:     0.7734806629834253\n",
      "    Note Length:  0.6496751624187906\n",
      "    Octave:       0.36628188681462825\n",
      "    Common Notes: 0.6600660066006601\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "---------------------------------------------\n",
      "Cumulative: 0.776099003068217\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.9836065573770493\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.7142857142857143\n",
      "    Cohesion:     0.7734806629834253\n",
      "    Note Length:  0.6996501749125438\n",
      "    Octave:       0.36628188681462825\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.776099003068217\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.9836065573770493\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.7142857142857143\n",
      "    Cohesion:     0.7734806629834253\n",
      "    Note Length:  0.6996501749125438\n",
      "    Octave:       0.36628188681462825\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7816517822341896\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.9836065573770493\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.7142857142857143\n",
      "    Cohesion:     0.7734806629834253\n",
      "    Note Length:  0.7496251874062969\n",
      "    Octave:       0.36628188681462825\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7872045614001623\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.9836065573770493\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.7142857142857143\n",
      "    Cohesion:     0.7734806629834253\n",
      "    Note Length:  0.79960019990005\n",
      "    Octave:       0.36628188681462825\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7927573405661347\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.9836065573770493\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.7142857142857143\n",
      "    Cohesion:     0.7734806629834253\n",
      "    Note Length:  0.8495752123938032\n",
      "    Octave:       0.36628188681462825\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7927573405661347\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.9836065573770493\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.7142857142857143\n",
      "    Cohesion:     0.7734806629834253\n",
      "    Note Length:  0.8495752123938032\n",
      "    Octave:       0.36628188681462825\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7927573405661347\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.9836065573770493\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.7142857142857143\n",
      "    Cohesion:     0.7734806629834253\n",
      "    Note Length:  0.8495752123938032\n",
      "    Octave:       0.36628188681462825\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.7983101197321072\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.9836065573770493\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.7142857142857143\n",
      "    Cohesion:     0.7734806629834253\n",
      "    Note Length:  0.8995502248875562\n",
      "    Octave:       0.36628188681462825\n",
      "    Common Notes: 0.6600660066006601\n",
      "---------------------------------------------\n",
      "Cumulative: 0.8304036548542049\n",
      "    Motion:       0.7908422837761446\n",
      "    Consonance:   0.9836065573770493\n",
      "    Consistency:  0.9966777408637875\n",
      "    Macroharmony: 1.0\n",
      "    Centricity:   0.7142857142857143\n",
      "    Cohesion:     0.6767955801104972\n",
      "    Note Length:  0.8995502248875562\n",
      "    Octave:       0.42177578248610437\n",
      "    Common Notes: 0.99009900990099\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "                <div id='midiPlayerDiv579'></div>\n",
       "                <link rel=\"stylesheet\" href=\"//cuthbertLab.github.io/music21j/css/m21.css\"\n",
       "                    type=\"text/css\" />\n",
       "                <script>\n",
       "                require.config({\n",
       "                    paths: {'music21': '//cuthbertLab.github.io/music21j/src/music21'}\n",
       "                });\n",
       "                require(['music21'], function() {\n",
       "                               mp = new music21.miditools.MidiPlayer();\n",
       "                               mp.addPlayer('#midiPlayerDiv579');\n",
       "                               mp.base64Load('data:audio/midi;base64,TVRoZAAAAAYAAQACBABNVHJrAAAAFAD/UQMHoSAA/1gEBAIYCIgA/y8ATVRyawAAAJMA/wMAAOAAQIgAkClajgCAKQDeAJAtWpAAgC0AkACQTFqYAIBMAJgAkElakgCASQAAkCxaAJAlWgCQJVqSAIAsAACAJQAAgCUAAJAqWpoAgCoAAJB0WgCQPVoAkElamgCAdAAAgD0AAIBJAM4AkDFaAJBGWgCQbVqaAIAxAACARgAAgG0AAJAQWoIAgBAAiAD/LwA=');\n",
       "                        });\n",
       "                </script>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "if __name__ == '__main__':\n",
    "    score = ScoreGenerator(population_size, dna_length, mute_rate, modifiers)\n",
    "    child = score.generate(target_score).getScore()\n",
    "    fp = child.write('midi', fp=r'./example.midi')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:Empty]",
   "language": "python",
   "name": "conda-env-Empty-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
